package com.coolingme.springboot.dubbo.springbootdubbosampleconsumer;

import com.coolingme.springboot.dubbo.ILoginService;
import com.coolingme.springboot.dubbo.ISayHelloService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class SpringBootDubboSampleConsumerApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringBootDubboSampleConsumerApplication.class, args);
    }

    /**
     * registry：配置多个服务注册地址
     * version：配置服务提供者的版本
     */
    @DubboReference(registry = {"nanjing", "shanghai"},
            protocol = "dubbo",
            version = "2.0",
            loadbalance = "roundrobin",
//            mock = "com.coolingme.springboot.dubbo.springbootdubbosampleconsumer.MockSayHelloServiceImpl",
            mock = "fail:return dubbofail",
//            mock = "force:return dubboforce",
            timeout = 500,
            cluster = "failfast",
            retries = 1,
//            cluster = "forking",
            check = false
    )
    ISayHelloService sayHelloService;

    @DubboReference(check = false)
    ILoginService loginService;

    @GetMapping("/say")
    public String sayHello() {
        String string = sayHelloService.sayHello("Joey");
        System.out.println(string);
        return string;
    }

    @GetMapping("/login/{user}/{password}")
    public String login(@PathVariable("user") String userName, @PathVariable("password") String password) {
        return loginService.login(userName, password);
    }

}
